package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @auther Mr.wang
 * @date 2024/11/14 - 16:27
 */
@Mapper
public interface AddressBookMapper {

    /**
     * 新增地址
     * @param addressBook
     */
    @Insert("        insert into sky_take_out.address_book (user_id, consignee, phone, sex, province_code, province_name, city_code, \n" +
            "                                               city_name, district_code, district_name, detail, label, is_default)\n" +
            "        values (#{userId},#{consignee},#{phone},#{sex},#{provinceCode},#{provinceName},#{cityCode},\n" +
            "                #{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void insert(AddressBook addressBook);



    /**
     * 查询当前用户的所有地址
     * @param addressBook
     */
    List<AddressBook> list(AddressBook addressBook);


    void update(AddressBook addressBook);

    @Select("select * from sky_take_out.address_book where id = #{id}")
    AddressBook getById(Long id);

    @Delete("delete from sky_take_out.address_book where id = #{id}")
    void deleteById(Long id);

    @Update("update sky_take_out.address_book set is_default = 0 where user_id = #{userId}")
    void updateIsDefaultByUserId(AddressBook addressBook);
}
